package org.example;

import javax.rmi.CORBA.Stub;
import java.io.*;
import java.util.ArrayList;

public class demo5 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
    /*
    * 序列化
    * */

    /*    //创建对象
        Student stu = new Student("男","lisi");
         Student stu2 = new Student("男","wangwu");
          Student stu3 = new Student("男","zhangsan");

        ArrayList<Student> list = new ArrayList<>();
        list.add(stu);
        list.add(stu2);
        list.add(stu3);


        //创建序列化对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("b.txt"));

        //写出数据
        oos.writeObject(list);

        //释放资源
        oos.close();
*/

        /*反序列化流*/
  ObjectInputStream ois = new ObjectInputStream(new FileInputStream("b.txt"));

//  Student o =(Student) ois.readObject();
        ArrayList<Student> list = (ArrayList<Student>) ois.readObject();

        for (Student student:list){
            System.out.println(student);
        }
//        System.out.println(o);

        ois.close();

    }
}
